﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using BussinessEntity;
using Utilities;
using BussinessLayer;

namespace PresentationLayer
{
    public partial class frmSearchService : DevComponents.DotNetBar.OfficeForm
    {
        public List<Service> Result { get; set; }
        public List<Service> list = ServiceManager.GetAll().Array;
        public frmSearchService()
        {
            InitializeComponent();
        }

        private void frmSearchDichVu_Load(object sender, EventArgs e)
        {
            cbSearchBy.Items.Add("Mã dịch vụ");
            cbSearchBy.Items.Add("Tên dịch vụ");
            cbSearchBy.Items.Add("Loại dịch vụ");
            cbSearchBy.SelectedIndex = 0;
        }

        private void cbKeywork_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void cbSearchBy_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbSearchBy.SelectedIndex != 2)
            {
                cbKeywork.DataSource = null;
                cbKeywork.DropDownStyle = ComboBoxStyle.DropDown;
                cbKeywork.DataSource = list;
                if (cbSearchBy.SelectedIndex == 0)
                {
                    cbKeywork.DisplayMember = cbKeywork.ValueMember = "ServiceID";
                    foreach (var item in list)
                    {

                        cbKeywork.AutoCompleteCustomSource.Add(item.ServiceID);
                    }
                }
                else
                    if (cbSearchBy.SelectedIndex == 1)
                    {
                        foreach (var item in list)
                        {
                            cbKeywork.AutoCompleteCustomSource.Add(item.ServiceName);
                        }
                        cbKeywork.DisplayMember = cbKeywork.ValueMember = "ServiceName";
                    }
                cbKeywork.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                cbKeywork.AutoCompleteSource = AutoCompleteSource.CustomSource;
            }
            else
            {
                cbKeywork.DropDownStyle = ComboBoxStyle.DropDownList;
                cbKeywork.DataSource = null;
                cbKeywork.Items.Add("Cài đặt phần mềm");
                cbKeywork.Items.Add("Sửa phần cứng");
                cbKeywork.Items.Add("Thay phần cứng");
                cbKeywork.SelectedIndex = 0;
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (cbSearchBy.SelectedIndex == 0)
            {
                Result = list.FindAll(s => s.ServiceID == cbKeywork.Text);
            }
            else
                if (cbSearchBy.SelectedIndex == 1)
                {
                    Result = list.FindAll(s => s.ServiceName.Contains(cbKeywork.Text));
                }
                else
                {
                    Result = list.FindAll(s => s.ServiceCategory == cbKeywork.Text);
                }
            if (Result.Count > 0)
                Close();
            else
            {
                MessageBox.Show("Không tìm thấy thông tin phù hợp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Result = null;
            Close();
        }
    }
}